//
//  DUSearchView.m
//  APP
//
//  Created by duyujin1 on 2021/9/2.
//

#import "DUSearchView.h"
#import <Masonry.h>

@interface DUSearchView()<UITextFieldDelegate>
@property(nonatomic,strong)UITextField * textField;

@end

@implementation DUSearchView
-(instancetype)initWithFrame:(CGRect)frame{
    if(self=[super initWithFrame:frame]){
        [self textField];
    }
    return self;
}

-(UITextField *)textField{
    if(!_textField){
        _textField=[[UITextField alloc] initWithFrame:CGRectZero];
        _textField.leftView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"search"]];
        _textField.leftViewMode=UITextFieldViewModeAlways;
        _textField.clearButtonMode=UITextFieldViewModeWhileEditing;
        _textField.backgroundColor = [UIColor whiteColor];
        _textField.placeholder=@"今日热点推荐";
        _textField.delegate=self;
        [self addSubview:_textField];
        [_textField mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self);
        }];
    }
    return _textField;
}

- (void)textFieldDidBeginEditing:(UITextField *)textField{

}


- (void)textFieldDidChangeSelection:(UITextField *)textField {

}

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    //收起键盘
    [_textField resignFirstResponder];
    //发起网络请求
    
    return YES;
}

@end
